package C;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringJoiner;

public class C65 {

    static class Node {
        Node lchild;
        Node rchild;
        int weight;
        int height;

        public Node(Node lc, Node rc, int weight, int height) {
            this.lchild = lc;
            this.rchild = rc;
            this.weight = weight;
            this.height = height;
        }
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] nums = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(getResult(nums));
    }

    public static String getResult(int[] nums) {
        PriorityQueue<Node> pq = new PriorityQueue<>((a,b)->
            a.weight!=b.weight ? a.weight-b.weight : a.height-b.height);

        for (int i = 0; i < nums.length; i++) {
            Node node = new Node(null,null,nums[i],0);
            pq.offer(node);
        }

        while(pq.size()>1) {
            Node lc = pq.poll();
            Node rc = pq.poll();
            int fa_weight = lc.weight+rc.weight;
            int fa_height = rc.height+1;

            Node fa = new Node(lc,rc,fa_weight,fa_height);
            pq.offer(fa);
        }

        Node root = pq.poll();
        StringJoiner sj = new StringJoiner(" ");
        midOrder(root,sj);
        return sj.toString();
    }

    public static void midOrder(Node root,StringJoiner sj) {
        if (root.lchild != null) {
            midOrder(root.lchild,sj);
        }
        sj.add(String.valueOf(root.weight));
        if (root.rchild != null) {
            midOrder(root.rchild,sj);
        }
    }
}
